<?
require_once('ConverterBase.php');

class TestConverter extends ConverterBase {
	protected function toDatatype($string) {
		return $string;
	}
	protected function toString($object) {
		return (string)$object;
	}
}

class ConverterBaseTest extends PHPUnit_Framework_TestCase {
	protected $c;
	protected function setUp() {
		$this->c= new TestConverter;
	}
	function testGetErrorMessage() {
		$this->assertNull($this->c->getErrorMessage());
	}
	function testSetErrorMessage() {
		$str= 'Test msg';
		$this->c->setErrorMessage($str);
		$this->assertEquals($str,$this->c->getErrorMessage());
	}
	function testGetDefault() {
		$this->assertNull($this->c->getDefault());
	}
	function testSetDefault() {
		$str= 'Test msg';
		$this->c->setDefault($str);
		$this->assertSame($str,$this->c->getDefault());
		$obj= new TestConverter;
		$this->c->setDefault($obj);
		$this->assertSame($obj,$this->c->getDefault());
	}
	function testNullToDatatype() {
		$this->assertNull($this->c->getAsDatatype(null));
		$str= 'Test msg';
		$this->c->setDefault($str);
		$this->assertSame($str,$this->c->getAsDatatype(null));
	}
	function testNullToString() {
		$this->assertNull($this->c->getAsString(null));
		$str= 'Test msg';
		$this->c->setDefault($str);
		$this->assertSame($str,$this->c->getAsString(null));
	}
}